from numpy import *
import os

def Nernst(temperature, valence, ext_Ca_conc, int_Ca_conc):
    ''' This function calculates the equilibrium potential using the Nerst
        equation'''
    R = 8315 # mJ/(K*Mol) Universal Gas Constant
    F = 96480 # C/Mol Faraday's constant
    T = 273.16 + temperature # convert from Celcius to Kelvin
    return ((R*T)/(valence*F))*log(ext_Ca_conc/int_Ca_conc)


def vd(x,V):
    ''' This function returns the voltage dependance of the various conductance saturation variables 
                                                   x[1]
        vd(x,V) =  x[0] + ---------------------------------------------------
                         x[2] + x[3]*exp((V+x[4])/x[5]) + exp((V+x[6])/x[7])     '''
    if x[3] == 0:
        return x[0] + x[1]/( x[2] + exp((V+x[6])/x[7])  )
    else:
        return x[0] + x[1]/( x[2] + x[3]*exp((V+x[4])/x[5]) + exp((V+x[6])/x[7])  )

def pick_config():
    ''' prompts user to choose cell config filename and returns the filename and directory where file is/would
        be archived.'''
    listing = os.listdir(".")
    cell_number = 0
    cells_dict = {}
    cell_list = ""
    for file in listing:
        if 'cell_config' in file:
            cell_number += 1
            tokens = file.split("_cell_config")
            cell_name = tokens[0]
            cells_dict[str(cell_number)] = [file,cell_name]
            cell_list += "%d) %s \n" % (cell_number, cell_name)

    print cell_list
    number_chosen = raw_input("Enter the number of the cell config file you'd like to run.     ")
    confirmation = raw_input("You have chosen to use %s as a config file.  Is this ok? [y]/n     " % (cells_dict[number_chosen][0]))
    while "n" in confirmation:
        print cell_list
        number_chosen = raw_input("Enter the number of the cell config file you'd like to run.     ")
        confirmation = raw_input("You have chosen to use %s as a config file.  Is this ok? [y]/n     " % (cells_dict[number_chosen][0]))
    return cells_dict[number_chosen]


